<?php include('includes/header.php');?>
<?php include(inc('repository.php'));?>
<?php
	$order_by = isset($_COOKIE['my_vocabulary_order'])?strtolower($_COOKIE['my_vocabulary_order']):NULL;
	$filter = isset($_COOKIE['my_vocabulary_filter'])?strtolower($_COOKIE['my_vocabulary_filter']):NULL;
	$total = Word::count(user_val('id'),$order_by,$filter);
	$page = isset($_REQUEST['page'])?intval($_REQUEST['page']):1;
	$words = Word::query_with_definition(user_val('id'),$order_by,$filter,$page);
	
?>
<div id="main">
	<div class="panel_title">
		<?php _("词库"); ?>
		<div class="panel_bar dropdown">
			<ul class="panel_menu">
		        <li>
		            <a href="#" class="sort"><?php _('排序')?><span class="arrow">▼</span></a>
		            <ul class="hidden order_by">
		                <li><a href="javascript:void(0)" <?php stylish_state('by_time',$order_by,'selected')?> value="by_time">按时间</a></li>
		                <li><a href="javascript:void(0)" <?php stylish_state('by_alphabet',$order_by,'selected')?> value="by_alphabet">按字母</a></li>
		                <?php if(!$filter):?>
		                	<li><a href="javascript:void(0)" <?php stylish_state('by_familiarity',$order_by,'selected')?> value="by_familiarity">按熟悉程序</a></li>
		           	 	<?php endif ?>
		            </ul>
		        </li>
		        <li>
		            <a href="#" class="sort"><?php _('熟悉程度')?><span class="arrow">▼</span></a>
		            <ul class="hidden filter">
		                <li>
		                	<a href="javascript:void(0)" <?php stylish_state(1,$filter,'selected')?> value="1">
		                	<?php e(familiarity(1))?>
		                	</a>
		                </li>
		                <li><a href="javascript:void(0)" <?php stylish_state(2,$filter,'selected')?> value="2">
		                	<?php e(familiarity(2))?>
		                </a></li>
		                <li><a href="javascript:void(0)" <?php stylish_state(3,$filter,'selected')?> value="3">
		                <?php e(familiarity(3))?>
		                </a></li>
		                <li><a href="javascript:void(0)" <?php stylish_state(4,$filter,'selected')?> value="4">
		                <?php e(familiarity(4))?>
		                </a></li>
		                <li><a href="javascript:void(0)" <?php stylish_state(5,$filter,'selected')?> value="5">
		                <?php e(familiarity(5))?>
		                </a></li>
		                <li class="horizontal_line"></li>
		                <li><a href="#" <?php stylish_state(NULL,$filter,'selected') ?>>所有</a></li>
		            </ul>
	        	</li>
	        </ul>
		</div>
	</div>
	<div id="word_list" class="content my_vocabulary">
		<?php if(isset($_SESSION['removed_user_word'])):?>
		<div class="response message_box success_message_box">
			单词&nbsp;<span class=highlight><?php e($_SESSION['removed_user_word']);?></span>&nbsp;已从你的词库中删除
		</div>
		<?php unset($_SESSION['removed_user_word'])?>
		<?php endif ?>
		<?php if(count($words)==0):?>
			<span>没有找到单词，现在就去</span><a href="/collect_words.php">收藏</a>吧!
		<?php else:?>
		<?php foreach($words as $word):?>
			<div class="word_list_item">
				<input type="hidden" class="data_word_id" value="<?php e($word['word_id']); ?>" />
				<input type="hidden" class="data_word" value="<?php e($word['word']); ?>" />
				<?php word_stylish_link($word['word'],$word['familiarity']); ?>
				<span class="definition"><?php e($word['definition'])?></span>
				<span class="time"><?php e(time_ago(strtotime($word['created_at'])))?></span>
				<span class="operation hidden">
					<a href="/word.php?word=<?php e(urlencode($word['word']))?>">查看</a>
					&nbsp;|&nbsp;
					<?php if($word['familiarity'] == 5): ?>
					<a href="javascript:void(0)" class="btn_i_forgot">我忘了</a>
					<?php else: ?>
					<a href="javascript:void(0)" class="btn_so_easy">太简单</a>
					<?php endif ?>
					&nbsp;|&nbsp;
					<a href="javascript:void(0)" class="remove_user_word remove_confirm" >删除</a>
				</span>
				<?php progress_bar(20*$word['familiarity'])?>
			</div>
		<?php endforeach?>
	<?php endif ?>
	</div>
	<?php
		pagination($total);
	?>
</div>
<?php get_footer();?>